package com.atguigu.user.service.serviceImpl;

import com.atguigu.Result;
import com.atguigu.user.domain.UserInfo;
import com.atguigu.user.mapper.UserInfoMapper;
import com.atguigu.user.service.UserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;


    /**
     * 更新个人信息
     * @param userInfo
     * @return
     */
    @Override
    public Result updateProfile(UserInfo userInfo) {
        //更新个人信息
        return userInfoMapper.updateById(userInfo)>0?Result.success("更新成功"):Result.error("更新失败");
    }

    /**
     * 获取个人信息
     * @return
     */
    @Override
    public Result getProfile() {
        UserInfo userInfo = userInfoMapper.selectById(UserHolder.getUser().getId());
        return userInfo==null?Result.error("获取个人信息失败，请检查原因"):Result.success(userInfo);
    }


}
